package com.cjwfuture.eyesspace;

import com.cjwfuture.eyesspace.utils.LogUtil;
import ohos.ace.ability.AceAbility;
import ohos.aafwk.content.Intent;

import java.util.ArrayList;
import java.util.List;

public class MainAbility extends AceAbility {
    private static final String TAG = MainAbility.class.getSimpleName();
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        requestPermission();
    }
    private void requestPermission() {
        String[] permissions = {
                "ohos.permission.READ_USER_STORAGE",
                "ohos.permission.WRITE_USER_STORAGE",
                "ohos.permission.DISTRIBUTED_DATASYNC"
        };
        List<String> applyPermissions = new ArrayList<>();
        for (String element : permissions) {
            LogUtil.info(TAG, "check permission: " + element);
            if (verifySelfPermission(element) != 0) {
                if (canRequestPermission(element)) {
                    applyPermissions.add(element);
                } else {
                    LogUtil.info(TAG, "user deny permission");
                }
            } else {
                LogUtil.info(TAG, "user granted permission: " + element);
            }
        }
        requestPermissionsFromUser(applyPermissions.toArray(new String[0]), 0);
    }
    @Override
    public void onStop() {
        super.onStop();
    }

}
